package x.java.lang;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import x.java.io.File;

/**
 * @author qiangli
 *
 */
public class Runtime {
	private static java.lang.Runtime rt = java.lang.Runtime.getRuntime();
	private static Runtime instance = new Runtime();

	private Runtime() {
	}
	
	public static Runtime getRuntime() {
		return instance;
	}
	
	public void addShutdownHook(Thread hook) {
		rt.addShutdownHook(hook);
	}

	public int availableProcessors() {
		return rt.availableProcessors();
	}

	private String[] parseCommand(String command) {
		return new String[]{command}; //FIXME
	}
	public Process exec(String cmd, String[] envp, File dir) throws IOException {
		return exec(parseCommand(cmd),envp,dir);
	}

	public Process exec(String cmd, String[] envp) throws IOException {
		return  exec(parseCommand(cmd),envp,null);
	}

	public Process exec(String cmd) throws IOException {
		return exec(parseCommand(cmd),null,null);
	}

	public Process exec(String[] cmdarray, String[] envp, File dir) throws IOException {
		Process p = new Process(cmdarray,envp,dir);
		Thread t = new Thread(p);
		t.start();
		return p;
	}

	public java.lang.Process exec(String[] cmdarray, String[] envp) throws IOException {
		return exec(cmdarray, envp,null);
	}

	public java.lang.Process exec(String[] cmdarray) throws IOException {
		return exec(cmdarray,null,null);
	}

	public void shutdown(int status) {
		rt.exit(status);
	}
	
	public void exit(int status) {
	}

	public long freeMemory() {
		return rt.freeMemory();
	}

	public void gc() {
		rt.gc();
	}

	public InputStream getLocalizedInputStream(InputStream in) {
		throw new RuntimeException("Not supported");
		//return rt.getLocalizedInputStream(in);
	}

	public OutputStream getLocalizedOutputStream(OutputStream out) {
		throw new RuntimeException("Not supported");
		//return rt.getLocalizedOutputStream(out);
	}

	public void halt(int status) {
		rt.halt(status);
	}

	public void load(String filename) {
		throw new RuntimeException("Not supported");
	}

	public void loadLibrary(String libname) {
		throw new RuntimeException("Not supported");
	}

	public long maxMemory() {
		return rt.maxMemory();
	}

	public boolean removeShutdownHook(Thread hook) {
		return rt.removeShutdownHook(hook);
	}

	public void runFinalization() {
		rt.runFinalization();
	}

	public long totalMemory() {
		return rt.totalMemory();
	}

	public void traceInstructions(boolean on) {
		rt.traceInstructions(on);
	}

	public void traceMethodCalls(boolean on) {
		rt.traceMethodCalls(on);
	}

}
